package com.rem.rabbitmq.ee.Gexchanges.topic;

import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.rem.rabbitmq.ee.RabbitMqUtils;


/**
 * @author Rem
 * @date 2021-12-23
 */

public class Consumer12 {

    public static void main(String[] args) throws Exception {

        Channel channel = RabbitMqUtils.getChannel();

        /**
         * 创建一个临时队列  队列名称随机
         * 当消费者断开和该队列的连接时，队列自动删除
         */
        String queue = channel.queueDeclare().getQueue();
        /**
         * 将临时队列绑定到交换机
         */
        channel.queueBind(queue, RabbitMqUtils.EXCHANGE_TOPIC, "*.blue");
        channel.queueBind(queue, RabbitMqUtils.EXCHANGE_TOPIC, "#.red");

        //消费回调
        DeliverCallback deliverCallback = (consumerTag, message) -> System.out.println("接收到的消息：" + new String(message.getBody()));

        //取消消费回调 如果在消费的时候队列被删除了
        CancelCallback cancelCallback = consumerTag -> System.out.println("消费消息被中断");

        System.out.println("消费者12 等待消费");
        channel.basicConsume(queue, true, deliverCallback, cancelCallback);
    }


}
